package com.huawei.appgallery.search.ui.card;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.Layout;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.MultiLineLabelLayout.d;
import com.huawei.appgallery.search.ui.bean.HotWordInfo;
import com.huawei.appgallery.search.ui.cardbean.HotWordCardBean;
import com.huawei.appmarket.service.exposure.bean.ExposureDetail;
import huawei.widget.HwTextView;
import java.util.ArrayList;
import java.util.List;
import o.cgz;
import o.chy;
import o.cuv.a;
import o.cuv.b;
import o.cuv.c;
import o.cuv.f;
import o.cux;
import o.dof;
import o.ContentManager;
import o.dyg;
import o.epv;
import o.CollectCheck;
import o.MinimumFactory;

public class HotWordCard extends HotWordBaseCard implements d {
    private HwTextView ʼ;
    private int ˊॱ = 0;
    private int ᐝ = 0;

    public HotWordCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        super.ˏ(view);
        ॱ((TextView) (HwTextView) view.findViewById(b.ʾ));
        this.ʼ = (HwTextView) view.findViewById(b.ॱᐝ);
        if (this.ʼ != null) {
            this.ʼ.setText(f.ˊॱ);
        }
        return this;
    }

    public void ˏ(CardBean cardBean) {
        if ((cardBean instanceof HotWordCardBean) && this.ˋ != null) {
            super.ˏ(cardBean);
            this.ˋ.setLayoutListener(this);
            HotWordCardBean hotWordCardBean = (HotWordCardBean) cardBean;
            if (this.ʿ == null) {
                return;
            }
            if (dof.ॱ(hotWordCardBean.v_())) {
                this.ʿ.setVisibility(4);
                return;
            }
            this.ʿ.setText(hotWordCardBean.v_());
            this.ʿ.setVisibility(0);
        }
    }

    public void ॱ(final chy o_chy) {
        super.ॱ(o_chy);
        if (o_chy != null && this.ʼ != null) {
            this.ʼ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ HotWordCard ˏ;

                public void onClick(View view) {
                    if (this.ˏ.ˊᐝ instanceof HotWordCardBean) {
                        this.ˏ.ˎ(((HotWordCardBean) this.ˏ.ˊᐝ).ˊ());
                        o_chy.ˏ(200, this.ˏ);
                        new Handler().postDelayed(new Runnable(this) {
                            final /* synthetic */ AnonymousClass1 ˋ;

                            {
                                this.ˋ = r1;
                            }

                            public void run() {
                                if (this.ˋ.ˏ.ʼॱ instanceof Activity) {
                                    ArrayList ˊ = this.ˋ.ˏ.ˊ();
                                    if (!CollectCheck.isEmpty((List) ˊ)) {
                                        dyg ॱ = dyg.ॱ();
                                        ExposureDetail exposureDetail = new ExposureDetail();
                                        exposureDetail.ˏ(System.currentTimeMillis());
                                        exposureDetail.ॱ(this.ˋ.ˏ.ˊᐝ.ॱˉ());
                                        exposureDetail.ˎ(ˊ);
                                        ॱ.ˎ(exposureDetail, this.ˋ.ˏ.ʻ);
                                        return;
                                    }
                                    return;
                                }
                                cux.ˏ.ˋ("HotWordCard", "The context is not instanceof Activity.");
                            }
                        }, 1000);
                    }
                }
            });
        }
    }

    private void ˎ(List<HotWordInfo> list) {
        if (CollectCheck.isEmpty((List) list)) {
            cux.ˏ.ˏ("HotWordCard", "The hotword list is empty.");
            return;
        }
        if (this.ʽ != null) {
            this.ʽ.clear();
        }
        this.ˊॱ += this.ᐝ;
        if (list.size() <= this.ˊॱ) {
            this.ॱॱ = list;
            this.ˊॱ = 0;
        } else {
            this.ॱॱ = list.subList(this.ˊॱ, list.size());
        }
        ˋ(this.ॱॱ);
    }

    protected void ˎ(int i, ToggleButton toggleButton) {
        if (i != 0 && toggleButton != null) {
            Context ˋ = ContentManager.getInstant().getContext();
            int ˋ2 = epv.ˋ(ˋ, 16);
            Drawable drawable = ˋ.getResources().getDrawable(c.ᐝ);
            drawable.setBounds(0, 0, ˋ2, ˋ2);
            if (MinimumFactory.getBoolValue(ˋ)) {
                toggleButton.setCompoundDrawables(drawable, null, null, null);
            } else {
                toggleButton.setCompoundDrawables(null, null, drawable, null);
            }
            int dimensionPixelSize = ˋ.getResources().getDimensionPixelSize(a.ˊ);
            toggleButton.setCompoundDrawablePadding(dimensionPixelSize);
            dimensionPixelSize += ((int) Layout.getDesiredWidth(toggleButton.getText(), toggleButton.getPaint())) + ˋ2;
            if (dimensionPixelSize < toggleButton.getMinWidth() - ˋ2) {
                dimensionPixelSize = (toggleButton.getMinWidth() - dimensionPixelSize) / 2;
                toggleButton.setPadding(dimensionPixelSize, toggleButton.getPaddingTop(), dimensionPixelSize, toggleButton.getPaddingBottom());
            }
        }
    }

    public void ˏ(int i) {
        this.ᐝ = i;
    }
}
